#ifndef __PORTING_H__
#define __PORTING_H__

#ifdef HAVE_CONFIG_H
  #include "config.h"
#endif

#if !defined(WINDOWS) && ( defined(_WIN32) || defined(_WIN64) )
  #define WINDOWS
#endif

#if defined(WINDOWS)

#include <windows.h>

/*  string APIs */
#define snprintf                       _snprintf
#define p_vsnprintf                    _vsnprintf
#define strcasecmp(str1, str2)         _stricmp(str1, str2)
#define strncasecmp(str1, str2, size)  _strnicmp(str1, str2, size)
#define strtok_r                       strtok_s
#define atoll(a)                       _atoi64((a))
#define llabs(a)                       _abs64((a))
#define strtoll                        _strtoi64


/*  file and directory APIs */

#define PATH_MAX   MAX_PATH

#define realpath(path, resolved_path)  _fullpath(resolved_path, path, MAX_PATH)
#define mkdir(dir, mode)               _mkdir(dir)
#define lseekl(fd, offset, origin)      _lseeki64(fd, offset, origin)
#define fseekl(fd, offset, origin)      _fseeki64(fd, offset, origin)
#define ftruncate(fd, size)            _chsize_s(fd, size)
#define getcwd(buffer, length)         _getcwd(buffer, length)
#define fileno                         _fileno

/*  process and time APIs */
#define getpid()                       _getpid()
#define popen                          _popen
#define pclose                         _pclose

#define localtime_r(time, tm)          localtime_s(tm, time)
#define ftime                          _ftime_s
#define timeb                          _timeb

#define sleep(sec)                      Sleep(1000*(sec))
#define usleep(usec)                    Sleep((usec)/1000)

#endif /* WINDOWS */

#endif